<?php

//Knowledge Management Controller By Teerapong Singthong.
class Logon extends Controller{
	//ฟังก์ชั่น เรียกฟอร์มสมัคร
	function signup(){
		$data["title"] = "Create an Account.";	//set title.
		$data["topic"] = "Create an Account.";
		$data['content'] = 'form/signup_form';
		$data['navigator'] = "&nbsp;&#8250;&nbsp;Register Account";
		$this->load->view('inc/one_cols',$data);
	}
	
	//ฟังก์ชั่น ที่ฟอร์ม action มา (สร้างสมาชิก)
	function create_member(){
		$this->load->library('form_validation');

		//field name.
		$this->form_validation->set_rules('firstname','Firstname','trim|required');

		if($this->form_validation->run() == FALSE){
			$this->load->view('msg/create_account_false');
		}
		else
		{
			//ถ้าไม่มีอะไรผิดพลาด โหลดโมเดล
			$this->load->model('member/member_model');

			if($query = $this->member_model->create_member()){
				
				$data["title"] = "Create an Account.";	//set title.
				$data["topic"] = "Create an Account Complete !";
				echo "ok";
				//$data['content'] = 'ok';
				//$this->load->view('inc/one_cols',$data);
			}
			else
			{
				$this->load->view('msg/create_account_false');
			}
		}
	}
	//check login .. validate
	function validate_credentials(){
		$this->load->model('member/member_model');
		$query = $this->member_model->validate();
		
		if($query){ //is true..
			redirect('site/member');
		}
		else // incorrect username or password
		{
			//$this->index();
			echo "false";
		}
		
	}
}